package com.example.a2205douyin;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;

/**
 * 帧动画
 */
public class DemoActivity extends AppCompatActivity {
    private ImageView iv;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        iv = (ImageView) findViewById(R.id.iv);
        //帧动画
        /*AnimationDrawable background = (AnimationDrawable) iv.getBackground();
        background.setOneShot(true);//只展示一次
        background.start();*/
    }

    public void anmi(View view) {
        /**
         * 补间动画调用方式
         */
       /* Animation animation = AnimationUtils.loadAnimation(this, R.anim.an);
        iv.startAnimation(animation);*/
        /**
         * 属性动画调用方式---ObjectAnimator
         */
        /**
         * 透明度
         */
        /*ObjectAnimator animator = ObjectAnimator.ofFloat(iv, "alpha", 1, 0, 1, 0, 1,0.5f);
        animator.setDuration(5000);
        animator.start();*/
        /**
         * 平移
         */
        /*ObjectAnimator animator = ObjectAnimator.ofFloat(iv, "translationX", 0, 600, 200, 300);
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(iv, "translationY", 0, 600, 200, 500);
        AnimatorSet set = new AnimatorSet();
        set.setDuration(3000);
        set.play(animator).with(animator1);
        set.start();*/
        /**
         * 缩放+摇摆
         */
       /* ObjectAnimator scaleX = ObjectAnimator.ofFloat(iv, "scaleX", 1, 0.5f,1).setDuration(3000);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(iv, "scaleY", 1, 0.5f,1).setDuration(3000);
        ObjectAnimator animator = ObjectAnimator.ofFloat(iv, "rotation", -30, 30,0).setDuration(3000);
        AnimatorSet set = new AnimatorSet();
        set.play(scaleX).with(scaleY).with(animator);
        set.start();*/
        /**
         * 差值器
         */
        /*ObjectAnimator animator = ObjectAnimator.ofFloat(iv, "translationX", 0, 600);
        animator.setInterpolator(new BounceInterpolator());//弹珠效果
        animator.setDuration(3000);
        animator.start();*/
        /**
         * 事件分发拦截
         */

    }
}